/*
 * @Description: 机构管理 - 接口
 * @Author: DHL
 * @Date: 2022-03-28 14:25:56
 * @LastEditors: DHL
 * @LastEditTime: 2022-04-06 16:21:15
 */

import { $get, $post, $put } from '@/utils/http'
import { ContentTypeEnum } from '@/constant/http'
import {
  OrganizationListResultModel,
  OrganizationModel,
  OrganizationPageParams,
  OrganizationPageResultModel,
  OrganizationResultModel
} from './model/organizationModel'
import { Result } from '@/model/baseModel'

/**
 * 分页查询
 */
export const apiOrganizationSearch = (searchParams: OrganizationPageParams) =>
  $get<OrganizationPageResultModel>({
    url: '/sys/twbOrganization/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiOrganizationGetById = (id: string) =>
  $get<OrganizationResultModel>({
    url: '/sys/twbOrganization/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiOrganizationSave = (saveParams: OrganizationModel) =>
  $post<OrganizationResultModel>({
    url: '/sys/twbOrganization/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiOrganizationUpdateById = (updateParams: OrganizationModel) =>
  $put<OrganizationResultModel>({
    url: '/sys/twbOrganization/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 批量删除信息
 */
export const apiOrganizationBatchDeleteByIds = (ids: string) =>
  $post<OrganizationResultModel>({
    url: '/sys/twbOrganization/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 批量逻辑删除
 */
export const apiOrganizationLogicDeleteById = (id: string) =>
  $post<OrganizationResultModel>({
    url: '/sys/twbOrganization/logicDeleteById',
    params: { id: id }
  })

/**
 * 机构树
 * @param searchParams
 * @returns
 */
export const apiOrganizationSearchTree = (searchParams?: OrganizationModel) =>
  $get<OrganizationListResultModel>({
    url: '/sys/twbOrganization/searchTree',
    params: searchParams
  })

/**
 * 组织机构树查询没有数据权限
 * @param searchParams
 * @returns
 */
export const apiOrganizationSearchTreeNotDataScope = (searchParams?: OrganizationModel) =>
  $get<OrganizationListResultModel>({
    url: '/sys/twbOrganization/searchTreeNotDataScope',
    params: searchParams
  })

/**
 * 重置SearchKey
 * @returns
 */
export const apiOrganizationResetSearchKey = () =>
  $get<OrganizationResultModel>({
    url: '/sys/twbOrganization/resetSearchKey'
  })

/**
 * 查询用户的所有机构信息
 */
export const apiOrganizationSearchUserOrgs = (userId: string) =>
  $get<OrganizationListResultModel>({
    url: '/sys/twbOrganization/searchUserOrgs',
    params: {
      userId: userId
    }
  })
